package com.cg.service.impl;

import com.cg.dao.BaseInfoMapper;
import com.cg.dto.BasePageDto;
import com.cg.entity.BaseInfo;
import com.cg.service.BaseInfoService;
import com.cg.vo.BaseInfoVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (BaseInfo)表服务实现类
 *
 * @author chengong
 * @since 2023-12-20 11:08:23
 */
@Service("baseInfoService")
public class BaseInfoServiceImpl implements BaseInfoService {
    @Resource
    private BaseInfoMapper baseInfoMapper;


    /**
     * 验证基础信息表code是否重复
     */
    @Override
    public Integer checkBaseCode(String baseCode) {
        return baseInfoMapper.checkBaseCode(baseCode);
    }

    /**
     * 基础信息展示
     */
    @Override
    public PageInfo<BaseInfoVo> baseList(BasePageDto basePageDto) {
        PageHelper.startPage(basePageDto.getPageNum(),basePageDto.getPageSize());
        List<BaseInfoVo> baseInfoVos = baseInfoMapper.baseList(basePageDto.getBaseInfo());
        PageInfo<BaseInfoVo> pageInfo = new PageInfo<>(baseInfoVos);
        return pageInfo;
    }

    /**
     * 创建基础信息
     */
    @Override
    public Integer insertBaseInfo(BaseInfo baseInfo) {
        Integer count = 0;
        try {
            count = baseInfoMapper.insertBaseInfo(baseInfo);
        }catch (Exception e){
            e.printStackTrace();
        }
        return count;
    }

    /**
     * 修改基础信息
     */
    @Override
    public Integer setBaseInfo(BaseInfo baseInfo) {
        return baseInfoMapper.setBaseInfo(baseInfo);
    }

    /**
     * 删除基础信息
     */
    @Override
    public Integer removeBaseInfo(Integer baseInfoId) {
        return baseInfoMapper.removeBaseInfo(baseInfoId);
    }


}
